#ifndef __PEBBLE_H
#define __PEBBLE_H

#ifdef	WIN32

typedef	char			sbyte;
typedef	unsigned char	ubyte;
typedef	WORD			ushort;
typedef	DWORD			uint;

extern HINSTANCE	inst;
extern HWND			window;

uint sysTick(void);

#else // WIN32

#include <stm32f10x.h>

#define	BACKUP_STEPS	BKP_DR1
#define	BACKUP_TMOFSL	BKP_DR3
#define	BACKUP_TMOFSH	BKP_DR4
//#define	BACKUP_SLEEPL	BKP_DR6
//#define	BACKUP_SLEEPH	BKP_DR7
#define	BACKUP_BOOTS	BKP_DR9
#define	BACKUP_EXTRA	BKP_DR10

#define	FLAG_NOPOWER	0x0001
#define	FLAG_USB		0x0002

#define	EXTI_GSINT	EXTI_Line13
#define	EXTI_WKUP	EXTI_Line0

#define	STATUS_BOOTING		0
#define	STATUS_PEDOMETER	1
#define	STATUS_CLOCK		2
#define	STATUS_CHARGING		3
#define	STATUS_SILENT		4
#define	STATUS_STANDBY		5
#define	STATUS_TAP			6
#define	STATUS_TIMEOUT		7
#define	STATUS_WAKEUP		8
#define	STATUS_POWERDOWN	9

#define	TIME_TAP		100

typedef int8_t			byte;
typedef uint8_t			ubyte;
typedef uint16_t		ushort;
typedef uint32_t		uint;
typedef struct _DEBUG	DEBUG;
typedef struct _REPORT	REPORT;
typedef struct _SAVE	SAVE;

//extern ubyte	clrSteps;
extern uint		curSteps;
extern ushort	flags;
extern ubyte	lowPower;
extern ubyte	status;
extern SAVE		savRam;
extern uint		timer;

struct _DEBUG{
	ushort	key;
	ushort	count;
	ushort	reserved[30];
};
struct _REPORT{
	ushort	versionI;
	ushort	versionV;

	ushort	tickLoI;
	ushort	tickLoV;
	ushort	tickHiI;
	ushort	tickHiV;

	ushort	offsetLoI;
	ushort	offsetLoV;
	ushort	offsetHiI;
	ushort	offsetHiV;

	ushort	voltBI;
	ushort	voltBV;
	ushort	voltCI;
	ushort	voltCV;
	ushort	voltSI;
	ushort	voltSV;

	ushort	tkChgLI;
	ushort	tkChgLV;
	ushort	tkChgHI;
	ushort	tkChgHV;

	ushort	tcChgCI;
	ushort	tcChgCV;
	ushort	tcChgVI;
	ushort	tcChgVV;

	ushort	currentLoI;
	ushort	currentLoV;
	ushort	currentHiI;
	ushort	currentHiV;

	ushort	yestdayLoI;
	ushort	yestdayLoV;
	ushort	yestdayHiI;
	ushort	yestdayHiV;
};
struct _SAVE{
	uint	signSav;
	uint	lstSync;
	uint	timeAdj;
	uint	timeOfs;
	uint	accBase;
};

__no_init SAVE savRom@0x08008000;

#endif // WIN32

#define FIRMWARE_VER    0x0001

#define HID_VENDOR      0x0482
#define HID_PRODUCT     0x5750

#define	RPT_VERSION		0x0001
#define	RPT_PRODUCT		0x0002
#define	RPT_TICKLO		0x0003
#define	RPT_TICKHI		0x0004
#define	RPT_OFFSETLO	0x0005
#define	RPT_OFFSETHI	0x0006
#define	RPT_VOLTB		0x0007
#define	RPT_VOLTC		0x0008
#define	RPT_VOLTS		0x0009
#define	RPT_TKCHGL		0x000b	// 11
#define	RPT_TKCHGH		0x000c	// 12
#define	RPT_TRCHGC		0x000d	// 13
#define	RPT_TRCHGV		0x000e	// 14
#define	RPT_ACCX		0x0010	// 16
#define	RPT_ACCY		0x0011	// 17
#define	RPT_ACCZ		0x0012	// 18
#define	RPT_STEPSLO		0x0014	// 20
#define	RPT_STEPSHI		0x0015	// 21
#define	RPT_ACCKLO		0x0016	// 22
#define	RPT_ACCKHI		0x0017	// 23
#define	RPT_CONFIG		0x0020	// 32
#define	RPT_RESET		0x8000
#define	RPT_FIRMWARE	0x8001
#define	RPT_DEBUG		0x8002
#define	RPT_DATAIMG		0x8010
#define	RPT_ACCREC		0x8011
#define	RPT_STEPREC		0x8012
#define	RPT_ACTREC		0x8013

#endif